import { OAuth2AccessToken } from "@/types/modules/auth";

const TOKEN_KEY = 'token';

const isLogin = () => {
  return Boolean(localStorage.getItem(TOKEN_KEY));
};

const getToken = () => {
  const token = localStorage.getItem(TOKEN_KEY)
  if (token !== null) {
    return (JSON.parse(token) as OAuth2AccessToken).access_token
  }
  return null
}

const setToken = (token: OAuth2AccessToken) => {
  localStorage.setItem(TOKEN_KEY, JSON.stringify(token));
};

const clearToken = () => {
  localStorage.removeItem(TOKEN_KEY);
};

export { isLogin, getToken, setToken, clearToken };
